class_name Villager
extends NonPlayableCharacter

@export var motionless : bool = true
@export var sprite_frames:Resource

const VILLAGER_SCENE: PackedScene = preload("res://npc/villager.tscn")

const WARRIOR = "WARRIOR"
const DOCTOR = "DOCTOR"
const SALESMAN_RED = "SALESMAN_RED"
const SALESMAN_BLUE = "SALESMAN_BLUE"
const UNCLE_KHAKI = "UNCLE_KHAKI"
const UNCLE_DARK_BLUE = "UNCLE_DARK_BLUE"
const UNCLE_WATHET = "UNCLE_WATHET"
const LADY_WATHET = "LADY_WATHET"
const LADY_DARK_BLUE = "LADY_DARK_BLUE"
const LADY_RED = "LADY_RED"

const YOUNG_MAN = "YOUNG_MAN"

const NPC_RESOURCES := {
	WARRIOR: preload("res://npc/resources/NPC-勇士-1.tres"),
	DOCTOR: preload("res://npc/resources/NPC-博士-1.tres"),
	SALESMAN_RED: preload("res://npc/resources/NPC-售货员-红色.tres"),
	SALESMAN_BLUE: preload("res://npc/resources/NPC-售货员-蓝色.tres"),
	UNCLE_KHAKI: preload("res://npc/resources/NPC-大叔-卡其色.tres"),
	UNCLE_WATHET: preload("res://npc/resources/NPC-大叔-浅蓝色.tres"),
	UNCLE_DARK_BLUE: preload("res://npc/resources/NPC-大叔-深蓝色.tres"),
	LADY_WATHET: preload("res://npc/resources/NPC-女士-浅蓝.tres"),
	LADY_DARK_BLUE: preload("res://npc/resources/NPC-女士-深蓝.tres"),
	LADY_RED: preload("res://npc/resources/NPC-女士-红色.tres"),
	YOUNG_MAN: preload("res://npc/resources/NPC-青年-1.tres")
}

var init_grid:Vector2i
var villager_name:String
var dialogue:Array[String]

func _ready() -> void:
	$AnimatedSprite2D.sprite_frames = sprite_frames
	move_cycles = randi_range(min_move_cycle, max_move_cycle)
	position = GridUtils.grid_to_world(init_grid)

static func new_villager(grid:Vector2i,type:String,name:String,motionless:bool,dialogue:Array[String])->Villager:
	var new_villager:Villager = VILLAGER_SCENE.instantiate()
	new_villager.init_grid = grid
	new_villager.sprite_frames = NPC_RESOURCES.get(type)
	new_villager.villager_name = name
	new_villager.motionless = motionless
	new_villager.dialogue = dialogue
	
	return new_villager
